//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    foldData0: [{
        value: "商品",
        id: 0,
        active: true
      },
      {
        value: "易码转账",
        id: 1,
        active: false
      },
    ],
    foldData1: [{
        value: "累计",
        id: 0,
        active: true
      },
      {
        value: "今日",
        id: 1,
        active: false
      },
      {
        value: "本周",
        id: 2,
        active: false
      },
      {
        value: "本月",
        id: 3,
        active: false
      },
    ],
    // 
    maskFlag: true,
    height0: "0",
    height1: "0",
    id0: 0,
    id1: 0,
    // 渲染数据
    img: "",
    saleNum: "",
    priceM: "",
    itemName: "",
    rankingList: [],
    pageIndex:1,
    imgUrl: baseJs.imgUrl,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.GetRankingList();
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetRankingList();
  },

  goodsOrBusiness: function() {
    var that = this;
    var height0 = this.data.height0;
    var height1 = this.data.height1;
    if (height0 == "0") {
      this.setData({
        height0: "auto",
        height1: "0",
        maskFlag: false
      })
    } else {
      this.setData({
        height0: "0",
        height1: "0",
        maskFlag: true
      })
    }
  },
  // 
  times: function() {
    var that = this;
    var height0 = this.data.height0;
    var height1 = this.data.height1;
    if (height1 == "0") {
      this.setData({
        height1: "auto",
        height0: "0",
        maskFlag: false
      })
    } else {
      this.setData({
        height1: "0",
        height0: "0",
        maskFlag: true
      })
    }
  },
  // 
  choose0: function(e) {
    console.log(e);
    var that = this;
    var id0 = this.data.id0;
    var foldData0 = this.data.foldData0;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = foldData0.length; i < len; ++i) {
      if (foldData0[i].value == value) {
        foldData0[i].active = true;
      } else {
        foldData0[i].active = false
      }
    }
    this.setData({
      value: value,
      foldData0: foldData0,
      id0: e.currentTarget.dataset.id,
      height0: "0",
      height1: "0",
      maskFlag: true,
      pageIndex:1,
      rankingList:[],
    })
    this.GetRankingList();
  },
  // 
  choose1: function(e) {
    console.log(e);
    var that = this;
    var id1 = this.data.id1;
    var foldData1 = this.data.foldData1;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = foldData1.length; i < len; ++i) {
      if (foldData1[i].value == value) {
        foldData1[i].active = true;
      } else {
        foldData1[i].active = false
      }
    }
    this.setData({
      value:value,
      foldData1: foldData1,
      id1: e.currentTarget.dataset.id,
      height0: "0",
      height1: "0",
      maskFlag: true,
      pageIndex: 1,
      rankingList: [],
    })
    this.GetRankingList();
  },
  // 列表
  GetRankingList: function() {
    var that = this;
    var id0 = this.data.id0;
    var id1 = this.data.id1;
    var pageIndex = this.data.pageIndex;
    var rankingList = this.data.rankingList;
    var img = this.data.img;
    var saleNum = this.data.saleNum;
    var priceM = this.data.priceM;
    var itemName = this.data.itemName;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetRankingList&Type=" + id1 + "&PageSize=10&PageIndex=" + pageIndex + "&opType=" + id0),
      success: function(res) {
        console.log("method=GetRankingList&Type=" + id0 + "&PageSize=10&PageIndex=" + pageIndex + "&opType=" + id1);
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          rankingList.push(json[i])
        }
        that.setData({
          rankingList: rankingList,
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        console.log(rankingList);
      }
    })

  },
  // 
  urlTap:function(e){
    var that = this;
    var id0 = this.data.id0;
    if (id0 == 0){
      var goodsId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/packageA/goodsDetail/goodsDetail?isArea=0&goodsId=' + goodsId,
      })
      
    }else{
      var businessId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/packageA/store/store?businessId=' + businessId,
      })
    }

  },
  // 
})